package com.jhd.fuzhou.view.login;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Application;
import android.content.SharedPreferences;

import com.epson.isv.eprinterdriver.Ctrl.EPrintManager;
import com.jhd.fuzhou.util.UtilHelper;
import com.jhd.fuzhou.util.tbs.ExceptionHandler;
import com.tencent.smtt.sdk.QbSdk;
import com.xuexiang.xui.XUI;

import java.util.LinkedList;
import java.util.List;

public class FuzhouApplication extends Application {
    private List<Activity> stepList=new LinkedList<>();
    private List<Activity> docList=new LinkedList<>();
    private List<Activity> punishmentList=new LinkedList<>();
    private List<Activity> taskList=new LinkedList<>();
    private  static FuzhouApplication instance;
    private String accessToken;//访问令牌
    private String userId;
    private String userName;//登录用户名
    private String password;
    private String deptId;
    private String name;
    private String gender;
    private String assistant;//"0"
    private String birthday;//"1992-08-06"
    private String city;//"抚州市"
    private String county;//"临川区"
    private String createTime;//"2021-09-29 00:00:00"
    private String createUser;//"admin"
    private String deptName;//"局领导"
    private String id;//"11ebdafc9f0538dead0a80bfd7c3a848"
    private String idNo;//"32062119920806651X"
    private String joinSuperviseWork;//"1"
    private String mobileActivateStatus;//"0"
    private String mobileNo;//"18068112798"
    private String mobileRegisterStatus;//"0"
    private String orgId;//"11ebdafc9f0538dead0a80bfd7c3a8ef"
    private String orgId2;//临时orgId
    private String orgName;//"抚州市卫生计生综合监督执法局"
    private String orgLevel;//"抚州市卫生计生综合监督执法局"
    private String province;//"江苏省"
    private String lawEnforceNo;//执法证号
    private String status;//"1"
    private String sysUserId;//"d3fd66552be811ec90ed00ff78961234"
    private String useSystem;//"1"
    private SharedPreferences.Editor userEditor;
    private SharedPreferences user;


    @Override
    public void onTerminate() {
        super.onTerminate();

        EPrintManager epManager = EPrintManager.instance();
        epManager.releaseEscprLib(getApplicationContext());

    }
    public synchronized  static FuzhouApplication getInstance(){
        if(null==instance){
            instance=new FuzhouApplication();
        }
        return instance;
    }
    public void addStepActivity(Activity activity){
        stepList.add(activity);
    }
    public void exitStep(){
        try{
            for(Activity activity:stepList){
                if(activity!=null){
                    activity.finish();
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    public void deleteStepActivity(Activity activity){
        stepList.remove(activity);
    }
    public void addDocActivity(Activity activity){
        docList.add(activity);
    }
    public void exitDoc(){
        try{
            for(Activity activity:docList){
                if(activity!=null){
                    activity.finish();
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    public void addPunishmentActivity(Activity activity){
        punishmentList.add(activity);
    }
    public void exitPunishment(){
        try{
            for(Activity activity:punishmentList){
                if(activity!=null){
                    activity.finish();
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    public void addTaskActivity(Activity activity){
        taskList.add(activity);
    }
    public void exitTask(){
        try{
            for(Activity activity:taskList){
                if(activity!=null){
                    activity.finish();
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    public void deleteDocActivity(Activity activity){
        docList.remove(activity);
    }
    /*@Override
    public void onLowMemory(){
        super.onLowMemory();
        System.gc();
    }*/

    public void setName(String name) {
        userEditor.putString("name", name);
        userEditor.commit();
        this.name = name;
    }

    public void setGender(String gender) {
        userEditor.putString("gender", gender);
        userEditor.commit();
        this.gender = gender;
    }

    public void setAssistant(String assistant) {
        userEditor.putString("assistant", assistant);
        userEditor.commit();
        this.assistant = assistant;
    }

    public void setBirthday(String birthday) {
        userEditor.putString("birthday", birthday);
        userEditor.commit();
        this.birthday = birthday;
    }

    public void setCity(String city) {
        userEditor.putString("city", city);
        userEditor.commit();
        this.city = city;
    }

    public void setCounty(String county) {
        userEditor.putString("county", county);
        userEditor.commit();
        this.county = county;
    }

    public void setCreateTime(String createTime) {
        userEditor.putString("createTime", createTime);
        userEditor.commit();
        this.createTime = createTime;
    }

    public void setCreateUser(String createUser) {
        userEditor.putString("createUser", createUser);
        userEditor.commit();
        this.createUser = createUser;
    }

    public void setDeptName(String deptName) {
        userEditor.putString("deptName", deptName);
        userEditor.commit();
        this.deptName = deptName;
    }

    public void setId(String id) {
        userEditor.putString("id", id);
        userEditor.commit();
        this.id = id;
    }

    public void setIdNo(String idNo) {
        userEditor.putString("idNo", idNo);
        userEditor.commit();
        this.idNo = idNo;
    }

    public void setJoinSuperviseWork(String joinSuperviseWork) {
        userEditor.putString("joinSuperviseWork", joinSuperviseWork);
        userEditor.commit();
        this.joinSuperviseWork = joinSuperviseWork;
    }

    public void setMobileActivateStatus(String mobileActivateStatus) {
        userEditor.putString("mobileActivateStatus", mobileActivateStatus);
        userEditor.commit();
        this.mobileActivateStatus = mobileActivateStatus;
    }

    public void setMobileNo(String mobileNo) {
        userEditor.putString("mobileNo", mobileNo);
        userEditor.commit();
        this.mobileNo = mobileNo;
    }

    public void setMobileRegisterStatus(String mobileRegisterStatus) {
        userEditor.putString("mobileRegisterStatus", mobileRegisterStatus);
        userEditor.commit();
        this.mobileRegisterStatus = mobileRegisterStatus;
    }

    public void setOrgId(String orgId) {
        userEditor.putString("orgId", orgId);
        userEditor.commit();
        this.orgId = orgId;
    }
    public void setOrgId2(String orgId2) {
        userEditor.putString("orgId2", orgId2);
        userEditor.commit();
        this.orgId2 = orgId2;
    }

    public void setOrgName(String orgName) {
        userEditor.putString("orgName", orgName);
        userEditor.commit();
        this.orgName = orgName;
    }
    public void setOrgLevel(String orgLevel) {
        userEditor.putString("orgLevel", orgLevel);
        userEditor.commit();
        this.orgLevel = orgLevel;
    }

    public void setProvince(String province) {
        userEditor.putString("province", province);
        userEditor.commit();
        this.province = province;
    }

    public void setStatus(String status) {
        userEditor.putString("status", status);
        userEditor.commit();
        this.status = status;
    }

    public void setSysUserId(String sysUserId) {
        userEditor.putString("sysUserId", sysUserId);
        userEditor.commit();
        this.sysUserId = sysUserId;
    }

    public void setLawEnforceNo(String lawEnforceNo) {
        userEditor.putString("lawEnforceNo", lawEnforceNo);
        userEditor.commit();
        this.lawEnforceNo = lawEnforceNo;
    }


    public String getLawEnforceNo() {
        String s=user.getString("lawEnforceNo",null);
        return s;
    }

    public void setUseSystem(String useSystem) {
        userEditor.putString("useSystem", useSystem);
        userEditor.commit();
        this.useSystem = useSystem;
    }


    public String getName() {
        String s=user.getString("name",null);
        return s;
    }

    public String getGender() {
        String s=user.getString("gender",null);
        return s;
    }

    public String getAssistant() {
        String s=user.getString("assistant",null);
        return s;
    }

    public String getBirthday() {
        String s=user.getString("birthday",null);
        return s;
    }

    public String getCity() {
        String s=user.getString("city",null);
        return s;
    }

    public String getCounty() {
        String s=user.getString("county",null);
        return s;
    }

    public String getCreateTime() {
        String s=user.getString("createTime",null);
        return s;
    }

    public String getCreateUser() {
        String s=user.getString("createUser",null);
        return s;
    }

    public String getDeptName() {
        String s=user.getString("deptName",null);
        return s;
    }

    public String getId() {
        String s=user.getString("id",null);
        return s;
    }

    public String getIdNo() {
        String s=user.getString("idNo",null);
        return s;
    }

    public String getJoinSuperviseWork() {
        String s=user.getString("joinSuperviseWork",null);
        return s;
    }

    public String getMobileActivateStatus() {
        String s=user.getString("mobileActivateStatus",null);
        return s;
    }

    public String getMobileNo() {
        String s=user.getString("mobileNo",null);
        return s;
    }

    public String getMobileRegisterStatus() {
        String s=user.getString("mobileRegisterStatus",null);
        return s;
    }

    public String getOrgId() {
        String s=user.getString("orgId",null);
        return s;
    }
    public String getOrgId2() {
        String s=user.getString("orgId2",null);
        return s;
    }

    public String getOrgName() {
        String s=user.getString("orgName",null);
        return s;
    }
    public String getOrgLevel() {
        String s=user.getString("orgLevel",null);
        return s;
    }

    public String getProvince() {
        String s=user.getString("province",null);
        return s;
    }

    public String getStatus() {
        String s=user.getString("status",null);
        return s;
    }

    public String getSysUserId() {
        String s=user.getString("sysUserId",null);
        return s;
    }

    public String getUseSystem() {
        String s=user.getString("useSystem",null);
        return s;
    }


    @SuppressLint("CommitPrefEdits")
    @Override
    public void onCreate() {
        super.onCreate();
        user = getSharedPreferences(UtilHelper.Cache.USER, MODE_PRIVATE);
        userEditor=user.edit();
        EPrintManager epManager = EPrintManager.instance();
        epManager.initEscprLib(getApplicationContext());
        //初始化UI框架
        XUI.init(this);
        //开启UI框架调试日志
        XUI.debug(true);

        //增加这句话
       // QbSdk.initX5Environment(this,null);
       // ExceptionHandler.getInstance().initConfig(this);
    }
    public String getAccessToken() {
        String s="Bearer " +user.getString("accessToken",null);
        return s;
    }

    public void setAccessToken(String accessToken) {
        userEditor.putString("accessToken", accessToken);
        userEditor.commit();
        this.accessToken = accessToken;
    }
    public String getUserId() {
        String s=user.getString("userId",null);
        return s;
    }

    public void setUserId(String userId) {
        userEditor.putString("userId", userId);
        userEditor.commit();
        this.userId = userId;
    }

    public String getUserName() {
        String s=user.getString("userName",null);
        return s;
    }

    public void setUserName(String userName) {
        userEditor.putString("userName", userName);
        userEditor.commit();
        this.userName = userName;
    }
    public String getPassword() {
        String s=user.getString("password",null);
        return s;
    }

    public void setPassword(String password) {
        userEditor.putString("password", password);
        userEditor.commit();
        this.password = password;
    }
    public String getDeptId() {
        String s=user.getString("deptId",null);
        return s;
    }

    public void setDeptId(String deptId) {
        userEditor.putString("deptId", deptId);
        userEditor.commit();
        this.deptId = deptId;
    }
    public void clearAll() {
        userEditor.clear();
        userEditor.commit();
    }
    /*清除除用户名和密码之外的数据*/
    public void clear() {
        String mm=user.getString("password",null);
        String yhm=user.getString("userName",null);
        userEditor.clear();
        userEditor.putString("userName", yhm);
        userEditor.putString("password", mm);
        userEditor.commit();
    }
}

